from django.contrib.contenttypes.models import ContentType
from django.db import models
from utils.models import BaseModel
from apps.users.models import User
# Create your models here.
class schoolSite(models.Model):
    areaname=models.CharField(max_length=11,verbose_name='场地名称',null=True)
    price =models.DecimalField(decimal_places=2,max_digits=2,default=0.00,verbose_name='价格')
    info_message=models.CharField(max_length=20,null=True,verbose_name='场地信息')
    start_time=models.IntegerField(null=True)
    end_time=models.IntegerField(null=True)
    def __str__(self):
        return '<场地名称:%s>' % self.areaname
    class Meta:
        verbose_name = '场地信息表'
        verbose_name_plural = verbose_name
    # date=models.DateField(auto_now_add=False,null=True)
    # STATUS_CHOICES = (
    #     (-1, "不可预约"),
    #     (0, "可预约"),
    #     (1, "教学占用"),
    #     (2, "社团占用"),
    #     (3, "教师占用"),
    #     (4, "其他不可用事项"),
    # )
    # status = models.SmallIntegerField(choices=STATUS_CHOICES, default=0, verbose_name="场地状态")

#开放信息表
class BookSite(models.Model):
    site=models.ForeignKey(schoolSite,on_delete=models.DO_NOTHING)
    date=models.DateField(auto_now_add=False,null=True)
    STATUS_CHOICES = (
        (-1, "不可预约"),
        (0, "可预约"),
        (1, "教学占用"),
        (2, "社团占用"),
        (3, "教师占用"),
        (4, "其他不可用事项"),
    )
    status = models.SmallIntegerField(choices=STATUS_CHOICES, default=0, verbose_name="场地状态")
    info=models.CharField(max_length=50,null=True,verbose_name='备注信息',default='无')
    TIME_CHOICES=(
        (-3, "12:00-13:00"),
        (-2, "13:00-14:00"),
        (-1, "14:00-15:00"),
        (0, "15:00-16:00"),
        (1,"16:00-17:00"),
        (2,"17:00-18:00"),
        (3,"18:00-19:00"),
        (4,"19:00-20:00"),
    )
    time_slot=models.SmallIntegerField(choices=TIME_CHOICES,default=1,verbose_name='时间段')
    class Meta:
        unique_together = (("site", "time_slot","status"),)
        verbose_name = '开放信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '<场地:%s--时间段%s--预约状态%s>' %(self.site,self.time_slot,self.status)
#预约信息表
class Reservation(BaseModel):
    site_ID=models.ForeignKey(BookSite,on_delete=models.DO_NOTHING)
    user=models.ForeignKey(User,on_delete=models.DO_NOTHING,verbose_name='用户名')
    pre_date_day=models.DateField(auto_now_add=True,verbose_name='预约日期',null=True)
    pre_date=models.DateTimeField(auto_now_add=True,verbose_name='用户预约完成的时间')
    STATUS_CHOICE=(
        (1,'预定成功'),
        (2,'预定失败，有校内其他事情冲突，详情可咨询微信7'),
        (3,'取消成功')
    )
    pre_status=models.SmallIntegerField(choices=STATUS_CHOICE,default=1,verbose_name='预定状态')
    class Meta:
        verbose_name = '预约信息表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return '<Id:%s--,用户--%s，日期--%s>' %(self.id,self.user,self.pre_date)

class BallTogether(BaseModel):
    name=models.CharField(max_length=20,null=True)
    holder=models.ForeignKey(User,on_delete=models.DO_NOTHING,verbose_name='组织者')
    deadline_time=models.DateTimeField(null=True,verbose_name='截止时间')
    begin_time=models.DateTimeField(null=True,verbose_name='开始时间')
    site=models.CharField(max_length=30,verbose_name='地点')
    max_people=models.IntegerField(default=2,verbose_name='限制人数')
    money=models.IntegerField(default=0,verbose_name='活动收费')
    EVENT_CHOICE=((1,'足球'),
                  (2,'篮球'),
                  (3,'羽毛球单打'),
                  (4,'羽毛球双打'),
                  (5,'网球'),
                  (6,'乒乓球'),
                  (7,'排球'),
                  (8,'跑步'))
    event=models.SmallIntegerField(choices=EVENT_CHOICE,default=1,verbose_name='约球项目',null=True)
    Introduce=models.TextField(max_length=40,null=True,verbose_name='活动介绍')
    hope_lever=models.CharField(max_length=10,null=True,verbose_name='希望等级')
    sign_num=models.IntegerField(default=0,verbose_name='已经报名人数')
    contact=models.CharField(max_length=20,null=True,verbose_name='组织者联系方式')
    PASS_CHOICE=((1,'审核通过'),(2,'审核不通过'),(3,'待审核'))
    pass_choice=models.SmallIntegerField(choices=PASS_CHOICE,default=3,verbose_name='审核状态')
    SEX_CHOICE=((1,'无'),(2,'女生'),(3,'男生'))
    limit_sex=models.SmallIntegerField(choices=SEX_CHOICE,default=1,verbose_name='性别限制')
    class Meta:
        verbose_name = '一起运动活动表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return '<项目:%s--,组织者--%s，审核--%s>' %(self.event,self.holder,self.pass_choice)


class spc_Activity(BaseModel):
    active =models.ForeignKey(BallTogether,on_delete=models.DO_NOTHING,verbose_name='活动id')
    user =models.ForeignKey(User,on_delete=models.DO_NOTHING,verbose_name='参与者')
    contact=models.CharField(max_length=20,null=True,verbose_name='参与者联系方式')
    class Meta:
        unique_together = (('user','active'),)
        verbose_name = '活动报名表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return '<活动id:%s--,参与者--%s>' %(self.active,self.user)